<%--
  Created by IntelliJ IDEA.
  User: dell
  Date: 2021/7/26
  Time: 10:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>权限</title>
    <link href="static/css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="static/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="static/css/animate.min.css" rel="stylesheet">
    <link href="static/css/myAlert.css" rel="stylesheet">
    <link href="static/css/style.min.css?v=4.0.0" rel="stylesheet"><base target="_blank">
    <style type="text/css">
        button{
            float: right;
        }
        .ibox-content{
            width: 700px;
            box-shadow: 2px 2px 5px #bababa;
        }
    </style>
</head>
<body>
<%--一级菜单--%>
<div style="width: 60%;margin-left: 20%;margin-top: 10%" class="allRole1">
    <h2 style="text-align: center ;color: #07c227">权限列表</h2>
    <table class="table table-hover" >
        <thead>
        <tr >
            <th>id</th>
            <th>名称</th>
            <th>路径</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody class="first">

        </tbody>
    </table>
</div>
<%--二级菜单--%>
<div style="width: 60%;margin-left: 20%;margin-top: 10%" class="allRole2">
    <h2 style="text-align: center ;color: #07c227">权限列表</h2>
    <table class="table table-hover" >
        <thead>
        <tr >
            <th>id</th>
            <th>名称</th>
            <th>路径</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody class="Two">

        </tbody>
    </table>
</div>
<%--修改表单--%>
<div class="ibox-content updatemsg" style="margin-left: 20%;margin-top: 10%">
    <form class="form-horizontal" action="updateMenuById" method="post">
        <h2 class="showid">修改信息</h2>
        <div class="form-group">
            <input type="hidden" class="newmsg" name="mid">
            <label class="col-sm-3 control-label">权限名称：</label>
            <div class="col-sm-8">
                <input type="text" placeholder="权限名称" class="form-control mname" name="mname">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">权限路径：</label>
            <div class="col-sm-8">
                <input type="text" placeholder="路径" class="form-control murl" name="murl">
            </div>
        </div>
        <input type="submit" class="btn btn-outline btn-success update no" value="确认修改"/>
        <input type="button" class="btn btn-outline btn-info no" value="取消修改"/>
    </form>
</div>
<script src="static/js/jquery.min.js?v=2.1.4"></script>
<script src="static/js/bootstrap.min.js?v=3.3.5"></script>
<script src="static/js/plugins/iCheck/icheck.min.js"></script>
<script src="static/js/myAlert.js"></script>
<script src="static/js/jquery.form.min.js"></script>
<script>
    $(function (){
        $(".allRole2").hide();
        $('.updatemsg').hide();
        //查询一级菜单
            $.ajax({
                url:"findAllFirstMenu",
                type:"post",
                dataType:"json",
                success:function (data){
                    for (let i = 0; i < data.length; i++) {
                        $(".first").append("   <tr>\n" +
                            "            <td id='mid'>"+data[i].mid+"</td>" +
                            "            <td>"+data[i].mname+"</td>" +
                            "            <td>"+data[i].murl+"</td>" +
                            "            <td><input type='button' class='btn btn-outline btn-warning' value='详情'/>" +
                            "                <input type='button' class='btn btn-outline btn-danger deleteF'value='删除'/></td>" +
                            "        </tr>")
                    }
                    var malert= {
                        title: "Tip",
                        msg: "操作成功",
                    }
                    $(".deleteF").click(function (){
                        MyAlert(malert);
                    })
                    $(".btn-warning").click(function (){
                        $(".allRole2").show();
                        $(".allRole1").hide();
                        let mid= $(this).parents("tr").find("#mid").text()
                        $.ajax({
                            url:"findTwoMenuByParent",
                            type: "post",
                            data:{mid:mid},
                            success:function (data){
                                $(".Two").html("");
                                for (let i = 0; i < data.length; i++) {
                                    $(".Two").append("   <tr>\n" +
                                        "            <td id='mid'>"+data[i].mid+"</td>" +
                                        "            <td id='mname'>"+data[i].mname+"</td>" +
                                        "            <td id='murl'>"+data[i].murl+"</td>" +
                                        "            <td><input type='button' class='btn btn-outline btn-warning change' value='修改'/>" +
                                        "                <input type='button' class='btn btn-outline btn-danger deleteT'value='删除'/></td>" +
                                        "        </tr>")
                                }
                                $(".Two").append("<button type='button' class='btn btn-block btn-outline btn-primary'>返回</button>")
                                //  返回按钮功能
                                $(".btn-primary").click(function (){
                                    $(".allRole1").show();
                                    $(".allRole2").hide();
                                })
                                //修改权限内容
                                $(".change").click(function (){
                                    let mid= $(this).parents("tr").find("#mid").text()
                                    let mname= $(this).parents("tr").find("#mname").text()
                                    let murl= $(this).parents("tr").find("#murl").text()
                                    $(".allRole2").hide();
                                    $(".updatemsg").show();
                                    $(".newmsg").val(mid);$(".mname").val(mname);$(".murl").val(murl);
                                })
                                var malert= {
                                    title: "Tip",
                                    msg: "操作成功",
                                }
                                $(".update").click(function (){
                                    MyAlert(malert);
                                })
                                //阻止form表单跳转
                                $(".form-horizontal").submit(function (){
                                    $(this).ajaxSubmit()
                                    return false;
                                })
                                //取消修改
                                $(".no").click(function (){
                                    $(".allRole2").show();
                                    $(".updatemsg").hide();
                                })
                                //删除
                                $('.deleteT').click(function (){
                                    let mid= $(this).parents("tr").find("#mid").text()
                                    $.ajax({
                                        url:"deleteMenu",
                                        type:"post",
                                        data:{mid:mid},
                                        success:function (data){
                                            if (data=="true"){
                                               alert("删除成功，请刷新页面")
                                            }
                                        }
                                    })
                                })
                            }
                        })
                    })
                    //删除一级菜单
                    $(".deleteF").click(function (){
                        let mid= $(this).parents("tr").find("#mid").text()
                        $.ajax({
                            url:"deleteMenuF",
                            type:"post",
                            data:{mid:mid},
                            success:function (data){
                                if (data=="true"){
                                    alert("删除成功，请刷新页面")
                                }
                            }
                        })
                    })
                }

            })
    })
</script>
</body>
</html>
